package com.jdew.thkj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.jdew.thkj.R;
import com.jdew.thkj.bean.CountyAreaBean;

import java.util.ArrayList;
import java.util.List;

public class ListViewAdapter extends BaseAdapter {
    private List<CountyAreaBean.DataBean> list;
    private LayoutInflater inflater;

    public ListViewAdapter(Context context, List<CountyAreaBean.DataBean> list) {
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    public List<CountyAreaBean.DataBean> getList() {
        return list;
    }

    public void setList(List<CountyAreaBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public String getItem(int position) {
        return list.get(position).getCountry();
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //加载布局为一个视图
        View view = inflater.inflate(R.layout.listview_item, null);
        TextView country = (TextView) view.findViewById(R.id.country);
        TextView countrycode = (TextView) view.findViewById(R.id.countrycode);
        country.setText(list.get(position).getCountry());
        countrycode.setText(list.get(position).getCountryID());
        return view;
    }
}